<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Cache,Event,Auth;
class EarthController extends Controller
{
	 public function index(){
	 	 return view('admin.earth.index');
	 }


	 //查市下的所有单位数量
	public function tjdw(request $request){
		$name = $request->name;
		if ($name) {
			if ($name == 1) {
				$city = DB::select("SELECT area.name, COUNT(*) as value FROM units INNER JOIN area on units.city = area.id WHERE   area.cid = 0 GROUP BY units.city,area.name");
				$json = array('result'=>$city);
				$jcity = json_encode($json,true);
				echo $jcity;
			}else{
				$newname['name'] = $name;
				$area = DB::table('area')->where($newname)->first();
				$oneid = $area->id;
				$city = DB::select("SELECT area.name, COUNT(*) as value FROM units INNER JOIN area on units.area = area.id WHERE   area.cid = ? GROUP BY units.city,area.name",[$oneid]);

				$json = array('result'=>$city);
				$jcity = json_encode($json,true);
				echo $jcity;
			}
		}
	}

	//查市下的所有单位数量
	public function tjmj(request $request){
		$name = $request->name;
		if ($name) {
			if ($name == 1) {
				$city = DB::select("SELECT area.name, COUNT(*) as value FROM admin_users INNER JOIN area on admin_users.city = area.id WHERE admin_users.role_id=15 AND area.cid = 0 GROUP BY admin_users.city,area.name");
				$json = array('result'=>$city);
				$jcity = json_encode($json,true);
				echo $jcity;
			}else{
				$newname['name'] = $name;
				$area = DB::table('area')->where($newname)->first();
				$oneid = $area->id;
				$city = DB::select("SELECT area.name, COUNT(*) as value FROM admin_users INNER JOIN area on admin_users.area = area.id WHERE admin_users.role_id=15 AND area.cid = ? GROUP BY admin_users.city,area.name",[$oneid]);

				$json = array('result'=>$city);
				$jcity = json_encode($json,true);
				echo $jcity;
			}
		}
	}

	
}